<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
    String base = request.getContextPath();
    request.setAttribute("base", base);
    response.setCharacterEncoding("utf-8");
    //no cache
    response.setHeader("Cache-Control","no-store");
    response.setHeader("Pragrma","no-cache");
    response.setDateHeader("Expires",0);
%>
<!doctype html>
<html lang="zh" class="pu">

<head>
    <!-- meta -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <!-- no cache -->
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <meta HTTP-EQUIV="expires" CONTENT="0">

    <!-- style -->
    <style>
        .divlink {
            width:86%;
            margin-left: 7%;
            border-bottom: solid 1px #BBB;
            text-align: center;;
        }
        .divlink span {
            color:#0099FF;
        }
        .divinfo {
            width:100%;
        }
        .divinfo button {
            margin:0px;
            padding: 0px;
            color:#888;
            border-radius: 0px;
            border:0px;
            background: rgba(0,0,0,0);
            text-align: left;
        }
        .divinfo div {
            margin-left: 5%;
            width: 90%;
            padding-top:5%;
            font-size: 0px;
        }
        .divinfo input {
            margin: 0px;
            color: #BBB;
            width: 55%;
            border: solid 1px #555;
            border-radius: 0px;
            padding-top: 2%;
            padding-bottom: 2%;
            padding-left: 2px;
            padding-right: 0px;
        }
    </style>

    <title>领取红包</title>
</head>

<body style="padding: 0px;margin: 0px; display: none;">
<!-- 菲遇账户 -->
<div id="div_tlt" style="width: 60%;margin-left: 20%;color: #BBB;padding-top: 5%;padding-bottom: 1%;text-align:center;">菲遇账户</div>
<div id="div_userinfo" style="width: 60%;margin-left: 20%;color: #333;padding-bottom: 1%;text-align:center;">${nick}（${fid}）</div>
<div id="div_link" class="divlink">
    <div style="font-size:0px;margin-bottom: 2%;">
        <span id="span_link1" style="padding-right: 5%;border-right: solid 1px #BBB;">更换账户</span>
        <span id="span_link2" style="padding-left: 5%;">领取记录</span>
    </div>
</div>
<div id="div_rem" style="width: 60%;margin-left: 20%;color: #BBB;padding-top: 2%;padding-bottom: 1%;text-align:center;">菲币余额</div>
<div id="div_feibi" style="width: 60%;margin-left: 20%;color: #333;text-align:center;">${feibi}</div>

<!-- 提交 -->
<div id="div_info" class="divinfo">
    <div>
        <button id="btn_fee">领取金额：</button>
        <input id="input_fee" type="text" value="本次领取金额（元）" onfocus="javascript:if(this.value=='本次领取金额（元）')this.value='';" onblur="javascript:if(this.value=='')this.value='本次领取金额（元）';">
    </div>
    <div id="div_info1" style="color: #D00;padding-top: 0%;display: none;">将扣除2000菲币</div>
    <div>
        <button id="btn_zfb" style="color:#888;">支付宝账号：</button>
        <input id="input_zfb" type="text" value="请输入支付宝账号" onfocus="javascript:if(this.value=='请输入支付宝账号')this.value='';" onblur="javascript:if(this.value=='')this.value='请输入支付宝账号';">
    </div>
    <div>
        <button id="btn_zfbname" style="color:#888;">支付宝实名：</button>
        <input id="input_zfbname" type="text" value="请输入支付宝认证名字" onfocus="javascript:if(this.value=='请输入支付宝认证名字')this.value='';" onblur="javascript:if(this.value=='')this.value='请输入支付宝认证名字';">
    </div>
</div>

<!-- 底部信息 -->
<div id="div_foo" style="width: 100%;margin-top: 10%">
    <c:if test="${not empty withdrawnotverified}">
        <div style="border-radius:5px; width: 90%;margin-left: 5%;background: #BBB;color:#FFF;text-align: center;padding-top: 3%;padding-bottom: 2.5%;">审核中，无法再次领取</div>
    </c:if>
    <c:if test="${empty withdrawnotverified}">
        <c:if test="${not empty todaywithdrawed}">
            <div style="border-radius:5px; width: 90%;margin-left: 5%;background: #BBB;color:#FFF;text-align: center;padding-top: 3%;padding-bottom: 2.5%;">今日已完成领取</div>
        </c:if>
        <c:if test="${empty todaywithdrawed}">
            <c:if test="${feibi>1999}">
                <div id="div_get" style="border-radius:5px; width: 90%;margin-left: 5%;background: #3ABD9E;color:#FFF;text-align: center;padding-top: 3%;padding-bottom: 2.5%;">领取红包</div>
            </c:if>
            <c:if test="${feibi<2000}">
                <div style="border-radius:5px; width: 90%;margin-left: 5%;background: #BBB;color:#FFF;text-align: center;padding-top: 3%;padding-bottom: 2.5%;">可领取红包不足100，无法领取</div>
            </c:if>
        </c:if>
    </c:if>
    <div id="div_tip" style="width: 88%;margin-left: 6%;color:#CCC;padding-top: 3%;">领取需知：扣除平台成本${rate}%，每日可领取1次，领取金额将在1-3个工作日内到账</div>
</div>

<!-- js -->
<script src="${base}/resources/js/zepto.min.js"></script>
<script src="${base}/resources/js/cookie_hold.js"></script>
<script src="${base}/resources/js/waiting.js?786896721"></script>
<script src="${base}/resources/js/checkstate.js?568975845"></script>

<script>
    var stopOper = true;
    $(document).ready(function(){
        //提取成功后刷新
//        var withs = getCookie("withdraw_success");
//        if (withs != null) {
//            alert (123456);
//            setCookie("withdraw_success", null, -1);
//            location.reload();
//        }

        //检查用户登录状态
        var uid = '${uid}';
        if (uid == '' || uid == null) {
            location.href = "${base}/common/login.htm?from=withdraw/index.htm&title=" + encodeURI(encodeURI("领取红包"));
            return;
        }
        else {
            var env = '${env}';
            if (uid == '123456' && env != 'dev') {
                location.href = "${base}/common/login.htm?from=withdraw/index.htm&title=" + encodeURI(encodeURI("领取红包"));
                return;
            }
        }

        //允许操作
        stopOper = false;

        //领取金额改变
        $('#input_fee').bind('input propertychange', function() {
            showDeduct();
        });

        //操作-领取红包
        $('#div_get').click(function() {
            getFee ();
        });

        //切换账户
        $('#span_link1').click(function() {
            logout();
        });

        //领取记录
        $('#span_link2').click(function() {
            location.href = "${base}/withdraw/list.htm?uid=${uid}&pagesize=20&etype=${etype}";
        });

        //计算显示尺寸
        countRect();
        $(window).resize(function () {
            countRect();
        });
        //显示内容
        $('body').show ();
    });

    function logout () {
        location.href = "${base}/common/login.htm?from=withdraw/index.htm&title=" + encodeURI(encodeURI("领取红包"));
    }

    function getFee () {
        if (stopOper) return;
        $('#div_info1').hide ();

        //有效金额
        var feibi = '${feibi}';
        if (isNaN (feibi)) {
            showInfo ('', '余额不足', 30);
            return;
        }
        //正确金额
        var fee = $('#input_fee').val();
        if (isNaN(fee)) {
            showInfo ('input_fee', '请输入正确的数字金额', 30);
            return;
        }
        //整百输入
        var grmb = parseInt (fee);
        var tmb = parseInt (grmb / 100) * 100;
        if (tmb < 100 || tmb != grmb) {
            showInfo ('input_fee', '请输入整百金额，如100', 30);
            return;
        }
        //余额足够
        var scale = parseInt(${scale});
        var nrmb = parseInt (feibi) / scale;
        if (grmb > nrmb) {
            showInfo ('input_fee', '领取金额大于余额，请重新输入', 30);
            return;
        }

        //支付宝账号
        var zfb = $('#input_zfb').val();
        if (zfb == null || zfb == '请输入支付宝账号') {
            showInfo ('input_zfb', '请输入支付宝账号', 45);
            return;
        }
        //输入格式验证
        var err = checkMobilePhone(zfb);
        if(err != null && err != '' && !checkEmail(zfb)) {
            showInfo ('input_zfb', '支付宝账号应为手机号或邮箱', 45);
            return;
        }

        //确认支付宝实名
        var zfbname = $('#input_zfbname').val();
        if (zfbname == null || zfbname == '请输入支付宝认证名字') {
            showInfo ('input_zfbname', '支付宝认证姓名不能为空', 50);
            return;
        }
        var czfbname = zfbname.replace(/ /g, "");
        if (czfbname.length == 0) {
            showInfo ('input_zfbname', '姓名不能为空格', 50);
            return;
        }

        //提现ajax
        stopOper = true;
        var uid = '${uid}';

        //创建请求标识信息
        if (uid == null || uid == '') uid = randomString(28);
        var reqid = uid + "_" + new Date().getTime();

        $.waiting.show ("请稍候...");
        $.ajax({
            url:"${base}/withdraw/add.htm?reqid=" + reqid + "&reqname=withdraw_add&uid=" + uid + "&amount=" + grmb + "&zfb=" + zfb + "&zfbname=" + zfbname,
            data: null,
            datatype: "text",
            success:function(data){
                var result1 = data.toString();
                if (result1 == "1") {
                    $.tips ("审核中，请等待审核结束");
                    location.href = window.location+ "?id=" + new Date().getTime();
                }
                else if (result1 == "2") {
                    $.tips ("对不起，今天已领取过了");
                    location.href = location.href + "?id=" + new Date().getTime();
                }
                else if (result1 == "3") {
                    $.tips ("对不起，余额不足");
                    location.href = location.href + "?id=" + new Date().getTime();
                }
                else if (result1 == "0") {
                    location.href = "${base}/withdraw/success.htm";
                }
                else {
                    $.tips ("领取红包失败，请重试");
                    location.href = location.href + "?id=" + new Date().getTime();
                }
            },
            error: function(XMLHttpRequest) {
                stopOper = false;
                alert('请求失败,XMLHttpRequest Status:' + XMLHttpRequest.status);
            },
            complete:function(XMLHttpRequest, textStatus){
                $.waiting.hide();
            }
        });
    }

    function showDeduct () {
        //正确金额
        var fee = $('#input_fee').val();
        if (isNaN(fee)) {
            $('#div_info1').hide();
            return;
        }

        //整百输入
        var grmb = parseInt (fee);
        var tmb = parseInt (grmb / 100) * 100;
        if (tmb < 100 || tmb != grmb) {
            $('#div_info1').hide();
            return;
        }

        //
        var scale = parseInt (${scale});
        $('#div_info1').text("将扣除" + (grmb * scale) + "菲币");
        $('#div_info1').show();
    }

    //提示信息
    function showInfo (foc, msg, top) {
        $.tips (msg, top + "%");
        if (foc != null && foc != '') $('#' + foc).focus();
    }

    //尺寸计算
    function countRect () {
        //
        if($(':focus').length != 0) return;

        //
        var ww,fsz;
        ww = parseInt ($(window).width());
        fsz = ww * 0.04;
        //菲遇账户
        $('#div_tlt').css('font-size', fsz);
        $('#div_userinfo').css('font-size', fsz);
        $('#div_link span').css('font-size', fsz);
        $('#div_rem').css('font-size', fsz);
        $('#div_feibi').css('font-size', fsz * 1.5);
        //提交
        $('#div_info button').css('font-size', fsz);
        $('#div_info input').css('font-size', fsz);
        var tw = ww * 0.9;
        var btnw = tw * 0.24 * 1.3;
        $('#div_info button').css('width', btnw);
        $('#div_info input').css('width', tw - btnw - 4);
        $('#div_info1').css('padding-left', btnw);
        $('#div_info1').css('width', tw - btnw);
        $('#div_info1').css('font-size', fsz * 0.8);
        //底部
        $('#div_get').css('font-size', fsz * 1.1);
        $('#div_tip').css('font-size', fsz);
    }
</script>

</body>
</html>